
NODE_ADDRESS=${1:-"172.19.182.191"}
HOSTNAME_OVERRIDE=${2:-"k8s-master-1"}
DNS_SERVER_IP=${3:-"10.254.0.2"}
DNS_DOMAIN=${4:-"cluster.local"}

KUBE_CFG_DIR=/opt/kubernetes/cfg
KUBE_SSL_DIR=/etc/kubernetes/ssl
KUBECONFIG_DIR=/opt/kubernetes/kubeconfig

cp ~/.kube/config ${KUBECONFIG_DIR}/kubelet.kubeconfig

cat <<EOF >/opt/kubernetes/cfg/kubelet.confing
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
address: ${NODE_ADDRESS}
port: 10250
readOnlyPort: 10255
cgroupDriver: cgroupfs
clusterDNS: ["${DNS_SERVER_IP}"]
clusterDomain: cluster.local.
failSwapOn: false
authentication:
  anonymous:
    enabled: true
EOF

cat <<EOF >/opt/kubernetes/cfg/kubelet
KUBE_LOGTOSTDERR="true"
KUBE_LOG_LEVEL="4"
KUBE_HOSTNAME_OVERRIDE="${HOSTNAME_OVERRIDE}"
KUBE_KUBECONFIG=${KUBECONFIG_DIR}/kubelet.kubeconfig
KUBE_BOOTSTRAP_KUBECONFIG=${KUBECONFIG_DIR}/bootstrap.kubeconfig
KUBE_CONFIG=${KUBE_CFG_DIR}/kubelet.confing
KUBE_CERT_DIR=${KUBE_SSL_DIR}
KUBE_POD_INFRA_CONTAINER_IMAGE=registry.cn-shanghai.aliyuncs.com/ms_google_containers/pause-amd64:3.1
EOF

cat <<EOF >/usr/lib/systemd/system/kubelet.service 
[Unit]
Description=Kubernetes Kubelet
After=docker.service
Requires=docker.service
 
[Service]
EnvironmentFile=/opt/kubernetes/cfg/kubelet
ExecStart=/opt/kubernetes/bin/kubelet \
--logtostderr=\${KUBE_LOGTOSTDERR} \
--v=\${KUBE_LOG_LEVEL} \
--hostname-override=\${KUBE_HOSTNAME_OVERRIDE} \
--kubeconfig=\${KUBE_KUBECONFIG} \
--bootstrap-kubeconfig=\${KUBE_BOOTSTRAP_KUBECONFIG} \
--config=\${KUBE_CONFIG} \
--cert-dir=\${KUBE_CERT_DIR} \
--pod-infra-container-image=\${KUBE_POD_INFRA_CONTAINER_IMAGE}

Restart=on-failure
KillMode=process
 
[Install]
WantedBy=multi-user.target
EOF


systemctl daemon-reload
systemctl enable kubelet
systemctl start kubelet
systemctl status kubelet

echo -e "\033[42;37m==kubelet配置完成===============================================================================\033[0m"

kubectl get csr
echo -e "\033[42;37m==加载Node===============================================================================\033[0m"
